Represent data hierarchy in sections
This example demonstrates how to use the Section component in the Scripting app to visually organize hierarchical data within a List. The content is structured by grouping related items—such as staff members by department—into labeled sections for better readability and navigation.
Overview
You will learn how to:
- Display structured data using
ListandSection - Group related items under section headers
- Create reusable row components for clarity
- Bind hierarchical data (Company → Departments → Staff) into a readable layout
Data Model
The example defines a three-level hierarchy representing a company structure:
Sample Data
Person Row Component
PersonRowView is a reusable component that displays a person's name and phone number with appropriate formatting.
Main View Layout
The main view uses a NavigationStack containing a List where each department is represented as a separate Section. The section header displays the department name, and each person is rendered using the PersonRowView.
Entry Point
The script presents the view and exits upon dismissal:
Key Components
- List: Provides a scrollable container for content.
- Section: Groups related items under a common header.
- NavigationStack: Enables title display and navigation context.
- Reusable View:
PersonRowViewensures clean, consistent row formatting.
Use Cases
- Grouping contacts by department or team
- Displaying categorized lists (e.g., tasks, inventory, regions)
- Organizing any data set that has a parent-child structure
Using Section within List improves both visual structure and user comprehension when working with hierarchical data.
